package edu.whu.rose.clock.kps.algorithm.blinks2.search3;


public class PotentialTree31 implements Comparable<PotentialTree31> {

	private short[] d2;
	
	private short[] distances;
	
	private int originBlock;
	
	public PotentialTree31(int l) {
		distances = new short[l];
		d2 = new short[l];
		for (int i = 0; i < l; i++) {
			distances[i] = Short.MAX_VALUE;
			d2[i] = Short.MAX_VALUE;
		}
	}
	
	public void setDistance(int i, short distance) {
		distances[i] = distance;
	}
	
	public short getDistance(int i) {
		return distances[i];
	}
	
	public int size() {
		return distances.length;
	}
	
	public short sumDistances() {
		short sum = (short)0;
		for (int i = 0; i < distances.length; i++) {
			if (distances[i] < Short.MAX_VALUE) {
				sum += distances[i];
			}
			else {
				return Short.MAX_VALUE;
			}
		}
		return sum;
	}
	
	public boolean isAnswer() {
		for (int i = 0; i < distances.length; i++) {
			if (distances[i] == Short.MAX_VALUE) {
				return false;
			}
		}
		return true;
	}

	public int compareTo(PotentialTree31 x) {
		if (sumDistances() > x.sumDistances()) {
			return 1;
		}
		else if (sumDistances() < x.sumDistances()) {
			return -1;
		}
		else {
			return 0;
		}
	}

	public short getD2(int i) {
		return d2[i];
	}

	public void setD2(int i, short d2) {
		this.d2[i] = d2;
	}

	public int getOriginBlock() {
		return originBlock;
	}

	public void setOriginBlock(int origin) {
		this.originBlock = origin;
	}

}
